package top.lywivan.mm.controller;

import top.lywivan.mm.common.GlobalConst;
import top.lywivan.mm.entity.Result;
import top.lywivan.mm.pojo.ReviewLog;
import top.lywivan.mm.pojo.User;
import top.lywivan.mm.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/review")
public class ReviewController {
    @Autowired
    private ReviewService reviewService;

    @PostMapping("/add")
    public Result addJingXuan(@RequestBody ReviewLog reviewLog, HttpSession session){
        System.out.println(reviewLog);
        User user = (User) session.getAttribute(GlobalConst.SESSION_KEY_USER);
        if (user==null){
            user=new User();
            user.setId(1);
        }
        reviewLog.setUserId(user.getId());
        reviewService.addJingXuan(reviewLog);
        return new Result(true,"添加成功");
    }
}
